package com.atguigu.gmall.order.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;

import java.io.IOException;

/**
 * @author lhh
 * @ClassName MqListener
 * @date 2022 2022/12/25
 */

//@Service
public class MqListener {

    //必须确认消息
   // @RabbitListener(queues = "haha")
    public void listen(Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        new String(message.getBody());
        System.out.println("正在处理");
        //业务处理
        try {
            channel.basicAck(deliveryTag,false);
            System.out.println(deliveryTag+"回复ok完成");
        } catch (IOException e) {
            //出现异常
            channel.basicNack(deliveryTag,false,true);
        }
    }
}
